package com.yang.refleciton;

/**
 * @author yds
 * @program java-annotation-and-reflection
 * @description java反射基础学习
 * 反射是java从静态语言转成伪动态语言
 * 通过反射机制获取编译后的Class再直接修改，让其能够动态编译，注解和反射是框架的基底
 * @create 2020-10-10 14:51
 **/
public class ReflecitonBase {
    /*
       获取Class类的几种方法
     */
    public static void main(String[] args) throws ClassNotFoundException {
        Class c1 = Integer.TYPE;
        System.out.println(c1 + "-->hashcode:" + c1.hashCode());
        //性能做高 .class方式
        Class c2 = Object.class;
        System.out.println(c2 + "-->hashcode:" + c2.hashCode());
        Class c3 = Class.forName("com.yang.refleciton.Refleciton");
        System.out.println(c3 + "-->hashcode:" + c3.hashCode());
        Demo01 d1=new Demo01();
        Demo01 d2=new Demo01();
        Class c4=d1.getClass();
        System.out.println(c4 + "-->hashcode:" + c4.hashCode());
        Class c5=d2.getClass();
        System.out.println(c5 + "-->hashcode:" + c5.hashCode());
        ClassLoader cl1 = d1.getClass().getClassLoader();
        Class c6 = cl1.loadClass("com.yang.refleciton.Demo01");
        System.out.println(c6 + "-->hashcode:" + c6.hashCode());
    }
}

/**
 * 类下面的所有实例获取的Class类都是同一个对象
 *
 */
class Demo01 {
    public Demo01() {
    }
}